﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ProxyPattern
{
    /// <summary>
    /// 真实的火车站
    /// </summary>
    public class RealSubject : ISubject
    {
        public RealSubject()
        {
            Thread.Sleep(5000);
            //而且很耗费资源  占内存
            Console.WriteLine("{0}被构造", this.GetType().Name);
        }

        /// <summary>
        /// 查询余票
        /// </summary>
        public void DoSomething()
        {
            Console.WriteLine("下面进入排队");
            Thread.Sleep(5000);
            Console.WriteLine("查询余票，有票");
        }

        /// <summary>
        /// 买票
        /// </summary>
        public void GetSomething()
        {
            //Cache
            Console.WriteLine("准备买票");
            long lResult = 0;
            for (int i = 0; i < 100000000; i++)//耗费资源
            {
                lResult += i;
            }
            Console.WriteLine("终于买好票了");
        }

    }
}
